package net.whg.aspect;

import net.whg.annotaion.TargetDataSource;
import net.whg.datasource.DynamicDataSource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DynamicDataSourceAspect {

    @Before("within(net.whg.service.impl.*) && " +
            "@annotation(targetDataSource)")
    public void before(JoinPoint joinPoint, TargetDataSource targetDataSource){
        String name = targetDataSource.value();
        DynamicDataSource.name.set(name);
        System.out.println("切换数据源：" + name);
    }
}
